<template>
  <div class="app-container">
    <h1>{{ blogTitle }}</h1>
    <AdvSearch
      :formLable="formItems"
      @onSearch="handleSearch"
      :getDatafunc="'getTableList'"
    ></AdvSearch>
    <el-table
      v-loading="listLoading"
      :data="list"
      element-loading-text="Loading"
      border
      fit
      highlight-current-row
      :header-cell-style="{ background: '#eef1f6' }"
    >
      <el-table-column align="center" label="ID" width="95">
        <template slot-scope="scope">
          {{ scope.$index }}
        </template>
      </el-table-column>
      <el-table-column label="Title">
        <template slot-scope="scope">
          {{ scope.row.title }}
        </template>
      </el-table-column>
      <el-table-column label="Title">
        <template slot-scope="scope">
          {{ scope.row.title }}
        </template>
      </el-table-column>
      <el-table-column label="Title">
        <template slot-scope="scope">
          {{ scope.row.title }}
        </template>
      </el-table-column>
      <el-table-column label="Title">
        <template slot-scope="scope">
          {{ scope.row.title }}
        </template>
      </el-table-column>
      <el-table-column label="Title">
        <template slot-scope="scope">
          {{ scope.row.title }}
        </template>
      </el-table-column>
      <el-table-column label="Title">
        <template slot-scope="scope">
          {{ scope.row.title }}
        </template>
      </el-table-column>
      <el-table-column label="Title">
        <template slot-scope="scope">
          {{ scope.row.title }}
        </template>
      </el-table-column>
      <el-table-column label="Title">
        <template slot-scope="scope">
          {{ scope.row.title }}
        </template>
      </el-table-column>
      <el-table-column label="Title">
        <template slot-scope="scope">
          {{ scope.row.title }}
        </template>
      </el-table-column>
      <el-table-column label="Author" width="110" align="center">
        <template slot-scope="scope">
          <span>{{ scope.row.author }}</span>
        </template>
      </el-table-column>
      <el-table-column label="Pageviews" width="110" align="center">
        <template slot-scope="scope">
          {{ scope.row.pageviews }}
        </template>
      </el-table-column>
      <el-table-column
        class-name="status-col"
        label="Status"
        width="110"
        align="center"
      >
        <template slot-scope="scope">
          <el-tag :type="scope.row.status | statusFilter">{{
            scope.row.status
          }}</el-tag>
        </template>
      </el-table-column>
      <el-table-column
        align="center"
        prop="created_at"
        label="Display_time"
        width="200"
      >
        <template slot-scope="scope">
          <i class="el-icon-time" />
          <span>{{ scope.row.display_time }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center">
        <template> </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
import { getList } from "@/api/table";
import AdvSearch from "@/components/Search/index.vue";
import Table from "@/components/Table/baseTable.vue";
export default {
  filters: {
    statusFilter(status) {
      const statusMap = {
        published: "success",
        draft: "gray",
        deleted: "danger",
      };
      return statusMap[status];
    },
  },
  data() {
    return {
      list: null,
      listLoading: true,
      blogTitle: "",
      searchForm: {},

      formItems: [
        {
          type: "input",
          label: "姓名",
          prop: "name",
        },
        {
          type: "select",
          label: "性别",
          prop: "sex",
          default: 0,
          options: [
            {
              id: 0,
              name: "男",
            },
            {
              id: 1,
              name: "女",
            },
          ],
        },
        {
          type: "datePicker",
          label: "出生日期",
          prop: "bridsday",
        },
        {
          type: "dateRangeArr",
          label: "活动时间",
          prop: "actvieTime",
        },
        {
          type: "dateRangeMulti",
          label: "报名时间",
          prop: ["startTime", "endTime"],
        },
      ],
    };
  },
  components: {
    AdvSearch,
    Table,
  },
  render(createElement) {
    return createElement("h1", this.blogTitle);
  },
  created() {
    this.fetchData();
  },
  methods: {
    handleSearch(e) {
      this.searchForm = e;
    },
    fetchData() {
      this.listLoading = true;
      getList().then((response) => {
        this.list = response.data.items;
        this.listLoading = false;
      });
    },
  },
};
</script>
